package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.request.payconfig.SubsidyDataRequest;
import com.ocom.common.vo.payconfig.SubsidyDataVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoSubsidyDataVo extends BaseMapper<SubsidyDataVo> {

    @Select({"<script>",
            "select  s.id , s.p_id, p.p_code, p.p_name, p.dept_id, a.acc_type_id as accType, \n" +
                    "s.plan_money, s.data_status,s.complete_money,  \n" +
                    "s.clear_money , s.grant_time as completeTime , s.wallet , p.p_tags as pTags    \n" +
                    "FROM subsidy_data s left join personnel_info p on p.p_id = s.p_id  \n" +
                    "left join xf_account_info a on a.p_id = s.p_id \n" +
                    "where s.com_id=#{comId} " +
                    "and s.times =#{times} " +
                    "and s.month_value =#{month} " +
                    " <when test=\"dataStatus !=null and  dataStatus !=0\" > "+
                        "  AND s.data_status =#{dataStatus}  "+
                    " </when> "+
                    " <when test=\"deptIdList !=null and deptIdList.size()>0 \" > "+
                        "AND p.dept_id in" +
                        "<foreach collection='deptIdList' item='item' open='(' separator=',' close=')'>" +
                            "#{item}" +
                        "</foreach>"+
                    " </when> "+
                    " <when test=\"accType > 0\" > "+
                        "  AND a.acc_type_id=#{accType} "+
                    " </when> "+
                    " <when test=\"pCode !=null and  pCode !=''\" > "+
                        " AND p.p_code LIKE concat('%', #{pCode}, '%')"+
                    " </when> "+
                    " <when test=\"pName !=null and  pName !=''\" > "+
                        "AND p.p_name LIKE concat('%', #{pName}, '%')"+
                    " </when> "+
                    " <when test='pTags != null' > "+
                    "<foreach collection='pTags' item='item' open=' AND  p.p_tags IS NOT NULL and (' separator='or' close=')'>" +
                    "  p.p_tags  like CONCAT(CONCAT('%,', #{item}), ',%') " +
                    "</foreach>"+
                    " </when> "+
                    "order by p.p_code,s.p_id" +
                    "</script>"})
    List<SubsidyDataVo> SubsidyDataVo(SubsidyDataRequest subsidyDataRequest);
}
